package com.warmheart.core.util.md5;

import java.security.MessageDigest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @ClassName: MD5Util
 * @Description: MD5工具类
 * @author hqkj
 * @date 2025-06-16 09:37:02
 *
 */
public class MD5Util {

    private final static Logger logger = LoggerFactory.getLogger(MD5Util.class);

    public static String MD5(String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] array = md.digest(data.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder();
            for (byte item : array) {
                sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString();
        } catch (Exception e) {
            logger.error("method:{} error:{}", "MD5Encode", e.getMessage());
        }
        return null;
    }

    public static void main(String[] args) {
        String dd = MD5("ewefwfewfwefwefwefwFWEFEAG4G54HRDTH");
        System.out.println(dd.length());
        System.out.println(dd);
    }
}
